package router

import (
	"gitee.com/liu_deping/gin-vue/controller"
	"gitee.com/liu_deping/gin-vue/middleware"
	"github.com/gin-gonic/gin"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()
	//路由组：user
	userRouter := r.Group("user")
	{
		userRouter.POST("/register", controller.Register)                     //请求类型：POST，路由:http://localhost:8080/user/register
		userRouter.POST("/login", controller.Login)                           //请求类型：POST，路由:http://localhost:8080/user/login
		userRouter.GET("/info", middleware.AuthMiddleware(), controller.Info) //请求类型：GET，路由:http://localhost:8080/user/info
	}
	//路由组：category
	categoryRouter := r.Group("/category")
	categoryController := controller.NewCatgoryController()
	{
		categoryRouter.POST("/add", categoryController.Add)
		categoryRouter.GET("/getall", categoryController.GetAll)
		categoryRouter.PUT("/update", categoryController.Update)
		categoryRouter.DELETE("/delete", categoryController.DeleteByID)
	}

	//路由组：category
	postRouter := r.Group("/post")
	postController := controller.NewPostController()
	{
		postRouter.POST("/add", postController.Add)
		postRouter.GET("/getall", postController.GetAll)
		postRouter.PUT("/update", postController.Update)
		postRouter.DELETE("/delete", postController.DeleteByID)
	}

	return r
}
